<cfparam default="none" name="url.api" />
<cfparam default="none" name="url.SCFStep3Beneficaries" />
<cfparam default="none" name="url.SCFStep3EmergencyContacts" />
<cfparam default="none" name="url.SCFStep3" />

<!--- get_position_details --->
<cfif url.api eq "get_position_details">
    <cfparam default="-1" name="url.id" />
    <cfswitch expression="#CGI.REQUEST_METHOD#">
        <cfcase value="GET">            
            <cfscript>
                KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
                PositionDetails = KronosQueries.funcGetPositionCode(url.id);
                retval = {
                    JobTitle = PositionDetails['JobCodeDescription'][1],
                    HoursPerYear = PositionDetails['StandardUnitsPerYear'][1],
                    SCF_UDF1 = PositionDetails['PositionCodeUserDefined1'][1],
                    SCF_UDF2 = PositionDetails['PositionCodeUserDefined2'][1],
                    SCF_UDF3 = PositionDetails['PositionCodeUserDefined3'][1],
                    WorkersCompCode = PositionDetails['PositionCodeUserDefined4'][1],
                    PayGradeCode = PositionDetails['PayGradeCode'][1],
                    PayGradeCodeDescription = PositionDetails['PayGradeCodeDescription'][1],
                    JobCode = PositionDetails['JobCode'][1]
                };
                writeOutput(SerializeJSON(retval));
            </cfscript>
        </cfcase>
    </cfswitch>
</cfif>
<!--- get_position_details --->



<!--- get_workers_details --->
<cfif url.api eq "get_workers_details" >    
    <cfparam default="-1" name="url.id" />
    <cfswitch expression="#CGI.REQUEST_METHOD#">
        <cfcase value="GET" >
            <cfscript>
                Utilities = CreateObject("component", session.rootDir & ".utilities.helperTools");
                WorkersComp = Utilities.funcGetWorkersCompID(url.id);
                writeOutput(SerializeJSON(WorkersComp));
            </cfscript>            
        </cfcase>    
    </cfswitch>
</cfif>
<!--- get_workers_details --->



<!--- Step3 adding beneficaries --->
<cfif url.SCFStep3Beneficaries eq "add" >
    <cfswitch expression="#CGI.REQUEST_METHOD#">
        <cfcase value="POST" >
            <cfscript>
                import models.*;
                KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");                
                StepAction = EntityLoad ("StepActions", FORM.StepID);
                Employee = EntityLoad("Employee", StepAction[1].getEmployeeID());
                Employee = Employee[1];
                StepAction = StepAction[1];
                Contacts = EntityNew("Contacts").init( Employee.getEmployeeID() );
                Contacts.setFirstName( FORM.First );
                Contacts.setLastName( FORM.Last );
                Contacts.setEmail( FORM.Email );
                Contacts.setAddress1( FORM.Address1 );
                Contacts.setAddress2( FORM.Address2 );
                Contacts.setCity( FORM.City );
                Contacts.setState( FORM.State );
                Contacts.setZip( FORM.Zip );
                Contacts.setHomePhone( Replace( FORM.HomePhone, "-", "", "All") );
                Contacts.setWorkPhone( Replace( FORM.WorkPhone, "-", "", "All") );
                Contacts.setCellPhone( Replace( FORM.CellPhone, "-", "", "All") );
                Contacts.setWorkPhoneExtention( FORM.WorkPhoneExt );
                Contacts.setPhonePrimaryID( FORM.PhonePrimaryID );
                Contacts.setRelationID( FORM.RelationID );
                Contacts.setContactTypeID(1);
                EntitySave(Contacts, true);
            </cfscript>            
        </cfcase>    
    </cfswitch>
</cfif>
<!--- Step3 adding beneficaries --->



<!--- Step3 Emergency Contacts --->
<cfif url.SCFStep3EmergencyContacts eq "add" >
    <cfswitch expression="#CGI.REQUEST_METHOD#">
        <cfcase value="POST" >
            <cfscript>
                import models.*;
                KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
                StepAction = EntityLoad ("StepActions", FORM.StepID);
                Employee = EntityLoad("Employee", StepAction[1].getEmployeeID());
                Employee = Employee[1];
                StepAction = StepAction[1];
                Contacts = EntityNew("Contacts").init( Employee.getEmployeeID() );
                Contacts.setFirstName( FORM.First );
                Contacts.setLastName( FORM.Last );
                Contacts.setEmail( FORM.Email );
                Contacts.setAddress1( FORM.Address1 );
                Contacts.setAddress2( FORM.Address2 );
                Contacts.setCity( FORM.City );
                Contacts.setState( FORM.State );
                Contacts.setZip( FORM.Zip );
                Contacts.setHomePhone( Replace( FORM.HomePhone, "-", "", "All") );
                Contacts.setWorkPhone( Replace( FORM.WorkPhone, "-", "", "All") );
                Contacts.setCellPhone( Replace( FORM.CellPhone, "-", "", "All") );
                Contacts.setWorkPhoneExtention( FORM.WorkPhoneExt );
                Contacts.setPhonePrimaryID( FORM.PhonePrimaryID );
                Contacts.setRelationID( FORM.RelationID );
                Contacts.setContactTypeID(2);
                EntitySave(Contacts, true);
            </cfscript>            
        </cfcase>    
    </cfswitch>
</cfif>
<!--- Step3 Emergency Contacts --->



<!--- Step3 Complete --->
<cfif url.SCFStep3 eq "complete" >
    <cfswitch expression="#CGI.REQUEST_METHOD#">
        <cfcase value="POST" >
            <cfscript>
                import models.*;
                StepAction = EntityLoad ("StepActions", FORM.StepID);
                Employee = EntityLoad("Employee", StepAction[1].getEmployeeID());
                Employee = Employee[1];
                StepAction = StepAction[1];                
                StepAction.setActionByID( Session.UserRosettaID );
                StepAction.setNotes( 'Completion of contacts' );
                StepAction.setActTimeStamp( DateFormat(now(), 'mm/dd/yyyy') );
                EntitySave(StepAction);
                InsertAction = EntityNew("StepActions");
                InsertAction.setEmployeeID( employee.getEmployeeID() );
                InsertAction.setStepsID(4);
                InsertAction.setCreationTimeStamp(now());
                EntitySave(InsertAction, true);
                
            </cfscript>
        </cfcase>    
    </cfswitch>
</cfif>
<!--- Step3 Complete --->



<!--- UserSearch --->
<cfif url.api eq "UserSearch">
    <cfswitch expression="#CGI.REQUEST_METHOD#">
        <cfcase value="GET">
            <cfparam default="" name="url.groupSearchString" />
            <cfscript>
                Users = createObject("component", "#session.rootDir#.utilities.Users").init();
                GetUserBYDN = Users.getADUserByDN(url.userSearchString);
                writeOutput(SerializeJSON(GetUserBYDN));
            </cfscript>
        </cfcase>
    </cfswitch>
</cfif>
<!--- UserSearch --->